home *** CD-ROM | disk | FTP | other *** search
- /* KNB Version 3.10 */
- /*
- File name: TESTFAD.C
- Description: This source file demonstrates the use of
- the Fader custom control in application programs. The
- base source code for this module was first generated
- using the CASE:W code generator in verbose mode.
- Sequence: This is Listing #4 */
-
- #define EXTERN
- #include "TESTFAD.h" /* Generated by CASE:W */
- #include "fadbox.h" /* Generated by SDK Dialog Box Editor */
- #include "fader.h" /* Needed for fader custom control */
-
- BOOL NEAR PASCAL RegisterControlClass (HANDLE hInstance);
-
- /************************************************************************/
- /* */
- /* Windows 3.0 Main Program Body */
- /* */
- /* The following routine is the Windows Main Program. The Main Program */
- /* is executed when a program is selected from the Windows Control */
- /* Panel or File Manager. The WinMain routine registers and creates */
- /* the program's main window and initializes global objects. The */
- /* WinMain routine also includes the applications message dispatch */
- /* loop. Every window message destined for the main window or any */
- /* subordinate windows is obtained, possibly translated, and */
- /* dispatched to a window or dialog processing function. The dispatch */
- /* loop is exited when a WM_QUIT message is obtained. Before exiting */
- /* the WinMain routine should destroy any objects created and free */
- /* memory and other resources. */
- /* */
- /************************************************************************/
-
- int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
- {
- /***********************************************************************/
- /* HANDLE hInstance; handle for this instance */
- /* HANDLE hPrevInstance; handle for possible previous instances */
- /* LPSTR lpszCmdLine; long pointer to exec command line */
- /* int nCmdShow; Show code for main window display */
- /***********************************************************************/
-
- MSG msg; /* MSG structure to store your messages */
- int nRc; /* return value from Register Classes */
- HANDLE hLibFader;
-
- strcpy(szarAppName, "TESTFAD");
- hInst = hInstance;
- if(!hPrevInstance)
- {
- /* register window classes if first instance of application */
- if ((nRc = nCwRegisterClasses()) == -1)
- {
- /* registering one of the windows failed */
- LoadString(hInst, IDS_ERR_REGISTER_CLASS, szarString, sizeof(szarString));
- MessageBox(NULL, szarString, NULL, MB_ICONEXCLAMATION);
- return nRc;
- }
- }
-
-
- /* create application's Main window */
- hWndMain = CreateWindow(
- szarAppName, /* Window class name */
- NULL, /* no title */
- WS_CAPTION | /* Title and Min/Max */
- WS_SYSMENU | /* Add system menu box */
- WS_MINIMIZEBOX | /* Add minimize box */
- WS_MAXIMIZEBOX | /* Add maximize box */
- WS_THICKFRAME | /* thick sizeable frame */
- WS_CLIPCHILDREN | /* don't draw in child windows areas */
- WS_VISIBLE | /* window created visible */
- WS_OVERLAPPED,
- CW_USEDEFAULT, 0, /* Use default X, Y */
- CW_USEDEFAULT, 0, /* Use default X, Y */
- NULL, /* Parent window's handle */
- NULL, /* Default to Class Menu */
- hInst, /* Instance of window */
- NULL); /* Create struct for WM_CREATE */
-
-
-
- if(hWndMain == NULL)
- {
- LoadString(hInst, IDS_ERR_CREATE_WINDOW, szarString, sizeof(szarString));
- MessageBox(NULL, szarString, NULL, MB_ICONEXCLAMATION);
- return IDS_ERR_CREATE_WINDOW;
- }
-
-
- ShowWindow(hWndMain, nCmdShow); /* display main window */
- hLibFader = LoadLibrary("FADER.DLL");
- if (hLibFader < 32)
- return(0);
-
- while(GetMessage(&msg, NULL, 0, 0)) /* Until WM_QUIT message */
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
-
- /* Do clean up before exiting from the application */
- CwUnRegisterClasses();
- FreeLibrary(hLibFader);
- return msg.wParam;
- } /* End of WinMain */
-
-
-
- /************************************************************************/
- /* */
- /* Main Window Procedure */
- /* */
- /* This procedure provides service routines for the Windows events */
- /* (messages) that Windows sends to the window, as well as the user */
- /* initiated events (messages) that are generated when the user selects */
- /* the action bar and pulldown menu controls or the corresponding */
- /* keyboard accelerators. */
- /* */
- /* The SWITCH statement shown below distributes the window messages to */
- /* the respective message service routines, which are set apart by the */
- /* CASE statements. The window procedures must provide an appropriate */
- /* service routine for its end user initiated messages, as well as the */
- /* general Windows messages (ie. WM_CLOSE message). If a message is */
- /* sent to this procedure for which there is no programmed CASE clause */
- /* (i.e., no service routine), the message is defaulted to the */
- /* DefWindowProc function, where it is handled by Windows */
- /* */
- /************************************************************************/
-
- LONG FAR PASCAL WndProc(HWND hWnd, WORD Message, WORD wParam, LONG lParam)
- {
- HMENU hMenu=0; /* handle for the menu */
- HBITMAP hBitmap=0; /* handle for bitmaps */
- HDC hDC; /* handle for the display device */
- HANDLE hPen=0; /* handle for the current pen */
- PAINTSTRUCT ps; /* holds PAINT information */
- int nRc=0; /* return code */
-
- switch (Message)
- {
- case WM_COMMAND:
- /* The Windows messages for action bar and pulldown menu items */
- /* are processed here. */
- switch (wParam)
- {
- case IDM_D_FADERS:
- /* Place User Code to respond to the */
- /* Menu Item Named "&Faders..." here. */
- {
- FARPROC lpfnFADBOXMsgProc;
-
- lpfnFADBOXMsgProc = MakeProcInstance((FARPROC)FADBOXMsgProc, hInst);
- nRc = DialogBox(hInst, (LPSTR)"FADBOX", hWnd, lpfnFADBOXMsgProc);
- FreeProcInstance(lpfnFADBOXMsgProc);
- }
- break;
-
- case IDM_D_EXIT:
- /* Place User Code to respond to the */
- /* Menu Item Named "E&xit" here. */
- DestroyWindow(hWnd);
- if (hWnd == hWndMain)
- PostQuitMessage(0); /* Quit the application */
- hWndMain = 0; /* Clear the handle */
- break;
-
- default:
- return DefWindowProc(hWnd, Message, wParam, lParam);
- break;
- }
- break; /* End of WM_COMMAND */
-
- case WM_CREATE:
- /* The WM_CREATE message is sent once to a window when the */
- /* window is created. The window procedure for the new window */
- /* receives this message after the window is created, but */
- /* before the window becomes visible. */
-
-
- break; /* End of WM_CREATE */
-
- case WM_MOVE: /* code for moving the window */
- break;
-
- case WM_SIZE: /* code for sizing client area */
- break; /* End of WM_SIZE */
-
-
- case WM_PAINT: /* code for the window's client area */
- /* Obtain a handle to the device context */
- /* BeginPaint will sends WM_ERASEBKGND if appropriate */
- memset(&ps, 0x00, sizeof(PAINTSTRUCT));
- hDC = BeginPaint(hWnd, &ps);
-
- /* Inform Windows painting is complete */
- EndPaint(hWnd, &ps);
- break; /* End of WM_PAINT */
-
- case WM_CLOSE: /* close the window */
- /* Destroy child windows, modeless dialogs, then, this window */
- DestroyWindow(hWnd);
- if (hWnd == hWndMain)
- PostQuitMessage(0); /* Quit the application */
- hWndMain = 0; /* Clear the handle */
- break; /* End of WM_CLOSE */
-
-
- default:
- /* For any message for which you don't specifically provide a */
- /* service routine, you should return the message to Windows */
- /* for default message processing. */
- return DefWindowProc(hWnd, Message, wParam, lParam);
- break; /* End of default */
- }
- return 0L;
- } /* End of WndProc */
- /************************************************************************/
- /* */
- /* Dialog Window Procedure */
- /* */
- /* This procedure is associated with the dialog box that is included in */
- /* the function name of the procedure. It provides the service routines */
- /* for the events (messages) that occur because the end user operates */
- /* one of the dialog box's buttons, entry fields, or controls. */
- /* */
- /* The SWITCH statement in the function distributes the dialog box */
- /* messages to the respective service routines, which are set apart by */
- /* the CASE clauses. Like any other Windows window, the Dialog Window */
- /* procedures must provide an appropriate service routine for their end */
- /* user initiated messages as well as for general messages (like the */
- /* WM_CLOSE message). */
- /* Dialog messages are processed internally by windows and passed to the*/
- /* Dialog Message Procedure. IF processing is done for a Message the */
- /* Message procedure returns a TRUE, else , for messages not explicitly */
- /* processed, it returns a FALSE */
- /* */
- /************************************************************************/
-
- BOOL FAR PASCAL FADBOXMsgProc(HWND hWndDlg, WORD Message, WORD wParam, LONG lParam)
- {
- int nRc; /* Return code from Dialog boxes */
- int nJ ; /* Counter */
- HANDLE hCtl; /* Handle to dialog controls */
- static char szarWorkBuf[64]; /* Work buffer for processing */
- static NPSTR lpszEndPtr; /* Temporary pointer. */
- char text_val[40];
- int x;
- BOOL lTranslated;
-
- switch(Message)
- {
- case WM_INITDIALOG:
- /* initialize working variables */
- nRc = 0;
- hCtl = 0;
- nJ = 0;
- strcpy(szarWorkBuf, "");
- lpszEndPtr = 0;
-
- SetDlgItemText(hWndDlg, FADER_EDIT, (LPSTR)"TESTING");
-
- break; /* End of WM_INITDLG */
-
- case WM_CLOSE:
- /* Closing the Dialog behaves the same as Cancel */
- /* PostMessage(hWndDlg, WM_COMMAND, IDCANCEL, 0L); */
- EndDialog(hWndDlg, TRUE);
- break; /* End of WM_CLOSE */
-
- case WM_COMMAND:
- switch(wParam)
- {
- case FADER_OK:
- /* Ignore data values entered into the controls */
- /* and dismiss the dialog window returning FALSE */
- EndDialog(hWndDlg, FALSE);
- break;
-
- case FADER_1:
- switch (HIWORD(lParam)) {
- case FDRN_THUMBTRACK:
- case FDRN_ENDFADER:
- /* User has changed the current value of the Fader */
- /* Request the current value from the Fader */
- x = (int) SendMessage(LOWORD(lParam), FDRM_GETLOGVALUE, 0, 0);
-
- wsprintf(text_val,"%d",x);
- SetDlgItemText(hWndDlg, FADER_EDIT, (LPSTR)text_val);
- break;
- }
- break;
-
- case FADER_EDIT:
- /* If the value in the edit box changes, we will set the
- fader to use this as the new logical position */
- if (HIWORD(lParam) == EN_CHANGE) {
- x = GetDlgItemInt(hWndDlg, FADER_EDIT, (BOOL FAR *)&lTranslated, FALSE);
- SendDlgItemMessage(hWndDlg, FADER_1, FDRM_SETLOGVALUE, x, 0);
- }
- break;
- }
- break; /* End of WM_COMMAND */
-
- default:
- return FALSE;
- }
- return TRUE;
- } /* End of FADBOXMsgProc */
-
-
- /************************************************************************/
- /* */
- /* nCwRegisterClasses Function */
- /* */
- /* The following function registers all the classes of all the windows */
- /* associated with this application. The function returns an error code */
- /* if unsuccessful, otherwise it returns 0. */
- /* */
- /************************************************************************/
-
- int nCwRegisterClasses(void)
- {
- WNDCLASS wndclass; /* struct to define a window class */
-
-
- /* load WNDCLASS with window's characteristics */
- wndclass.style = CS_HREDRAW | CS_VREDRAW;
-
- wndclass.lpfnWndProc = WndProc;
-
- /* Extra storage for Class and Window objects */
- wndclass.cbClsExtra = 0;
- wndclass.cbWndExtra = 0;
- wndclass.hInstance = hInst;
- wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
-
- /* Create brush for erasing background */
- wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wndclass.lpszMenuName = szarAppName; /* Class Name is Menu Name */
- wndclass.lpszClassName = szarAppName; /* Class Name is Window Name */
-
- if(!RegisterClass(&wndclass))
- return -1;
-
- return 0;
- } /* End of nCwRegisterClasses */
-
-
-
- /************************************************************************/
- /* CwUnRegisterClasses Function */
- /* */
- /* Deletes any refrences to windows resources created for this */
- /* application, frees memory, deletes instance, handles and does */
- /* clean up prior to exiting the window */
- /* */
- /************************************************************************/
-
- void CwUnRegisterClasses(void)
- {
- WNDCLASS wndclass; /* struct to define a window class */
- memset(&wndclass, 0x00, sizeof(WNDCLASS));
-
- UnregisterClass(szarAppName, hInst);
-
-
- } /* End of CwUnRegisterClasses */
-
-
-